<!DOCTYPE html><html class=split lang=en-US-x-hixie><script src=../link-fixup.js defer=""></script>
<!-- Mirrored from html.spec.whatwg.org/multipage/server-sent-events.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 10 Sep 2025 08:35:54 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<meta charset=utf-8><meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name=viewport><title>HTML Standard</title><meta content=#3c790a name=theme-color><meta content="light dark" name=color-scheme><link rel=stylesheet href=../../resources.whatwg.org/standard-shared-with-dev.css crossorigin=""><link rel=stylesheet href=../../resources.whatwg.org/standard.css crossorigin=""><link rel=stylesheet href=../../resources.whatwg.org/spec.css crossorigin=""><link rel=icon href=https://resources.whatwg.org/logo.svg crossorigin=""><link rel=stylesheet href=../styles.css crossorigin=""><script>
   function toggleStatus(div) {
     div.parentNode.classList.toggle('wrapped');
   }
   function setLinkFragment(link) {
     link.hash = location.hash;
   }
  </script><body>
  
  <script defer="" crossorigin="" src=../html-dfn.js></script>
  
  <header id=head class="head with-buttons">
   <a href=https://whatwg.org/ class=logo><img width=100 alt=WHATWG crossorigin="" class=darkmode-aware src=https://resources.whatwg.org/logo.svg height=100></a>
   <hgroup><h1 class=allcaps>HTML</h1><p id=living-standard>Living Standard — Last Updated <span class=pubdate>10 September 2025</span></hgroup>
   
   

   
  </header>

  

  

  

  
  

  
  

  

  <nav><a href=comms.html>← 9 Communication</a> — <a href=index.html>Table of Contents</a> — <a href=web-messaging.html>9.3 Cross-document messaging →</a></nav><ol class=toc><li id=toc-comms><ol><li><a href=server-sent-events.html#server-sent-events><span class=secno>9.2</span> Server-sent events</a><ol><li><a href=server-sent-events.html#server-sent-events-intro><span class=secno>9.2.1</span> Introduction</a><li><a href=server-sent-events.html#the-eventsource-interface><span class=secno>9.2.2</span> The <code>EventSource</code> interface</a><li><a href=server-sent-events.html#sse-processing-model><span class=secno>9.2.3</span> Processing model</a><li><a href=server-sent-events.html#the-last-event-id-header><span class=secno>9.2.4</span> The `<code>Last-Event-ID</code>` header</a><li><a href=server-sent-events.html#parsing-an-event-stream><span class=secno>9.2.5</span> Parsing an event stream</a><li><a href=server-sent-events.html#event-stream-interpretation><span class=secno>9.2.6</span> Interpreting an event stream</a><li><a href=server-sent-events.html#authoring-notes><span class=secno>9.2.7</span> Authoring notes</a><li><a href=server-sent-events.html#eventsource-push><span class=secno>9.2.8</span> Connectionless push and other features</a><li><a href=server-sent-events.html#garbage-collection><span class=secno>9.2.9</span> Garbage collection</a><li><a href=server-sent-events.html#implementation-advice><span class=secno>9.2.10</span> Implementation advice</a></ol></ol></ol><h3 id=server-sent-events><span class=secno>9.2</span> <dfn>Server-sent events</dfn><a href=#server-sent-events class=self-link></a></h3><div class="mdn-anno wrapped"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events title="Traditionally, a web page has to send a request to the server to receive new data; that is, the page requests data from the server. With server-sent events, it's possible for a server to send new data to a web page at any time, by pushing messages to the web page. These incoming messages can be treated as Events + data inside the web page.">Server-sent_events</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>5+</span></span><span class="chrome yes"><span>Chrome</span><span>6+</span></span><hr><span class="opera yes"><span>Opera</span><span>11+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>5+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>11+</span></span></div></div></div>

  <h4 id=server-sent-events-intro><span class=secno>9.2.1</span> Introduction<a href=#server-sent-events-intro class=self-link></a></h4>

  <p><i>This section is non-normative.</i></p>

  <p>To enable servers to push data to web pages over HTTP or using dedicated server-push protocols,
  this specification introduces the <code id=server-sent-events-intro:eventsource><a href=#eventsource>EventSource</a></code> interface.</p>

  <p>Using this API consists of creating an <code id=server-sent-events-intro:eventsource-2><a href=#eventsource>EventSource</a></code> object and registering an event
  listener.</p>

  <pre><code class='js'><c- a>var</c-> source <c- o>=</c-> <c- k>new</c-> EventSource<c- p>(</c-><c- t>&apos;updates.cgi&apos;</c-><c- p>);</c->
source<c- p>.</c->onmessage <c- o>=</c-> <c- a>function</c-> <c- p>(</c->event<c- p>)</c-> <c- p>{</c->
  alert<c- p>(</c->event<c- p>.</c->data<c- p>);</c->
<c- p>};</c-></code></pre>

  <p>On the server-side, the script ("<code>updates.cgi</code>" in this case) sends
  messages in the following form, with the <code id=server-sent-events-intro:text/event-stream><a href=iana.html#text/event-stream>text/event-stream</a></code> MIME type:</p>

  <pre>data: This is the first message.

data: This is the second message, it
data: has two lines.

data: This is the third message.</pre>

  <hr>

  <p>Authors can separate events by using different event types. Here is a stream that has two event
  types, "add" and "remove":</p>

  <pre>event: add
data: 73857293

event: remove
data: 2153

event: add
data: 113411</pre>

  <p>The script to handle such a stream would look like this (where <code>addHandler</code>
  and <code>removeHandler</code> are functions that take one argument, the event):</p>

  <pre><code class='js'><c- a>var</c-> source <c- o>=</c-> <c- k>new</c-> EventSource<c- p>(</c-><c- t>&apos;updates.cgi&apos;</c-><c- p>);</c->
source<c- p>.</c->addEventListener<c- p>(</c-><c- t>&apos;add&apos;</c-><c- p>,</c-> addHandler<c- p>,</c-> <c- kc>false</c-><c- p>);</c->
source<c- p>.</c->addEventListener<c- p>(</c-><c- t>&apos;remove&apos;</c-><c- p>,</c-> removeHandler<c- p>,</c-> <c- kc>false</c-><c- p>);</c-></code></pre>

  <p>The default event type is "message".</p>

  <p>Event streams are always decoded as UTF-8. There is no way to specify another character
  encoding.</p>

  <hr>

  <p>Event stream requests can be redirected using HTTP 301 and 307 redirects as with normal HTTP
  requests. Clients will reconnect if the connection is closed; a client can be told to stop
  reconnecting using the HTTP 204 No Content response code.</p>

  <p>Using this API rather than emulating it using <code id=server-sent-events-intro:xmlhttprequest><a data-x-internal=xmlhttprequest href=https://xhr.spec.whatwg.org/#xmlhttprequest>XMLHttpRequest</a></code> or an
  <code id=server-sent-events-intro:the-iframe-element><a href=iframe-embed-object.html#the-iframe-element>iframe</a></code> allows the user agent to make better use of network resources in cases where
  the user agent implementer and the network operator are able to coordinate in advance. Amongst
  other benefits, this can result in significant savings in battery life on portable devices. This
  is discussed further in the section below on <a href=#eventsource-push>connectionless
  push</a>.</p>


  <h4 id=the-eventsource-interface><span class=secno>9.2.2</span> The <code id=the-eventsource-interface:eventsource><a href=#eventsource>EventSource</a></code> interface<a href=#the-eventsource-interface class=self-link></a></h4><div class="mdn-anno wrapped"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/EventSource title="The EventSource interface is web content's interface to server-sent events.">EventSource</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>5+</span></span><span class="chrome yes"><span>Chrome</span><span>6+</span></span><hr><span class="opera yes"><span>Opera</span><span>11+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>5+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>11+</span></span></div></div></div>

  <pre><code class='idl'>[<c- g>Exposed</c->=(<c- n>Window</c->,<c- n>Worker</c->)]
<c- b>interface</c-> <dfn id='eventsource' data-dfn-type='interface'><c- g>EventSource</c-></dfn> : <a id='the-eventsource-interface:eventtarget' href='https://dom.spec.whatwg.org/#interface-eventtarget' data-x-internal='eventtarget'><c- n>EventTarget</c-></a> {
  <a href='#dom-eventsource' id='the-eventsource-interface:dom-eventsource'><c- g>constructor</c-></a>(<c- b>USVString</c-> <c- g>url</c->, <c- b>optional</c-> <a href='#eventsourceinit' id='the-eventsource-interface:eventsourceinit'><c- n>EventSourceInit</c-></a> <c- g>eventSourceInitDict</c-> = {});

  <c- b>readonly</c-> <c- b>attribute</c-> <c- b>USVString</c-> <a href='#dom-eventsource-url' id='the-eventsource-interface:dom-eventsource-url'><c- g>url</c-></a>;
  <c- b>readonly</c-> <c- b>attribute</c-> <c- b>boolean</c-> <a href='#dom-eventsource-withcredentials' id='the-eventsource-interface:dom-eventsource-withcredentials'><c- g>withCredentials</c-></a>;

  // ready state
  <c- b>const</c-> <c- b>unsigned</c-> <c- b>short</c-> <a href='#dom-eventsource-connecting' id='the-eventsource-interface:dom-eventsource-connecting'><c- g>CONNECTING</c-></a> = 0;
  <c- b>const</c-> <c- b>unsigned</c-> <c- b>short</c-> <a href='#dom-eventsource-open' id='the-eventsource-interface:dom-eventsource-open'><c- g>OPEN</c-></a> = 1;
  <c- b>const</c-> <c- b>unsigned</c-> <c- b>short</c-> <a href='#dom-eventsource-closed' id='the-eventsource-interface:dom-eventsource-closed'><c- g>CLOSED</c-></a> = 2;
  <c- b>readonly</c-> <c- b>attribute</c-> <c- b>unsigned</c-> <c- b>short</c-> <a href='#dom-eventsource-readystate' id='the-eventsource-interface:dom-eventsource-readystate'><c- g>readyState</c-></a>;

  // networking
  <c- b>attribute</c-> <a id='the-eventsource-interface:eventhandler' href='webappapis.html#eventhandler'><c- n>EventHandler</c-></a> <a href='#handler-eventsource-onopen' id='the-eventsource-interface:handler-eventsource-onopen'><c- g>onopen</c-></a>;
  <c- b>attribute</c-> <a id='the-eventsource-interface:eventhandler-2' href='webappapis.html#eventhandler'><c- n>EventHandler</c-></a> <a href='#handler-eventsource-onmessage' id='the-eventsource-interface:handler-eventsource-onmessage'><c- g>onmessage</c-></a>;
  <c- b>attribute</c-> <a id='the-eventsource-interface:eventhandler-3' href='webappapis.html#eventhandler'><c- n>EventHandler</c-></a> <a href='#handler-eventsource-onerror' id='the-eventsource-interface:handler-eventsource-onerror'><c- g>onerror</c-></a>;
  <c- b>undefined</c-> <a href='#dom-eventsource-close' id='the-eventsource-interface:dom-eventsource-close'><c- g>close</c-></a>();
};

<c- b>dictionary</c-> <dfn id='eventsourceinit' data-dfn-type='dictionary'><c- g>EventSourceInit</c-></dfn> {
  <c- b>boolean</c-> <dfn data-dfn-for='EventSourceInit' id='dom-eventsourceinit-withcredentials' data-dfn-type='dict-member'><c- g>withCredentials</c-></dfn> = <c- b>false</c->;
};</code></pre>

  

  <p>Each <code id=the-eventsource-interface:eventsource-2><a href=#eventsource>EventSource</a></code> object has the following associated with it:</p>

  <ul><li><p>A <dfn data-dfn-for=EventSource id=concept-eventsource-url>url</dfn> (a <a id=the-eventsource-interface:url-record href=https://url.spec.whatwg.org/#concept-url data-x-internal=url-record>URL
   record</a>). Set during construction.<li><p>A <dfn id=concept-event-stream-request>request</dfn>. This must initially be
   null.<li><p>A <dfn id=concept-event-stream-reconnection-time>reconnection time</dfn>, in
   milliseconds. This must initially be an <a id=the-eventsource-interface:implementation-defined href=https://infra.spec.whatwg.org/#implementation-defined data-x-internal=implementation-defined>implementation-defined</a> value, probably in
   the region of a few seconds.<li><p>A <dfn id=concept-event-stream-last-event-id>last event ID string</dfn>. This must
   initially be the empty string.</ul>

  <p>Apart from <a href=#concept-eventsource-url id=the-eventsource-interface:concept-eventsource-url>url</a> these are not currently exposed on
  the <code id=the-eventsource-interface:eventsource-3><a href=#eventsource>EventSource</a></code> object.</p>

  

  <dl class=domintro><dt><code><var>source</var> = new <a href=#dom-eventsource id=dom-eventsource-dev>EventSource</a>(
   <var>url</var> [, { <a href=#dom-eventsourceinit-withcredentials id=the-eventsource-interface:dom-eventsourceinit-withcredentials>withCredentials</a>:
   true } ])</code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/EventSource/EventSource title="The EventSource() constructor returns a newly-created EventSource, which represents a remote resource.">EventSource/EventSource</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>5+</span></span><span class="chrome yes"><span>Chrome</span><span>6+</span></span><hr><span class="opera yes"><span>Opera</span><span>11+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>5+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12+</span></span></div></div></div><dd>
    <p>Creates a new <code id=the-eventsource-interface:eventsource-4><a href=#eventsource>EventSource</a></code> object.</p>

    <p><var>url</var> is a string giving the <a id=the-eventsource-interface:url href=https://url.spec.whatwg.org/#concept-url data-x-internal=url>URL</a> that will provide the event
    stream.</p>

    <p>Setting <code id=the-eventsource-interface:dom-eventsourceinit-withcredentials-2><a href=#dom-eventsourceinit-withcredentials>withCredentials</a></code> to true
    will set the <a href=https://fetch.spec.whatwg.org/#concept-request-credentials-mode id=the-eventsource-interface:concept-request-credentials-mode data-x-internal=concept-request-credentials-mode>credentials mode</a> for
    connection requests to <var>url</var> to "<code>include</code>".</p>
   <dt><code><var>source</var>.<a href=#dom-eventsource-close id=dom-eventsource-close-dev>close</a>()</code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/EventSource/close title="The close() method of the EventSource interface closes the connection, if one is made, and sets the EventSource.readyState attribute to 2 (closed).">EventSource/close</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>5+</span></span><span class="chrome yes"><span>Chrome</span><span>6+</span></span><hr><span class="opera yes"><span>Opera</span><span>12+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>5+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12+</span></span></div></div></div><dd>
    <p>Aborts any instances of the <a href=https://fetch.spec.whatwg.org/#concept-fetch id=the-eventsource-interface:concept-fetch data-x-internal=concept-fetch>fetch</a> algorithm started for
    this <code id=the-eventsource-interface:eventsource-5><a href=#eventsource>EventSource</a></code> object, and sets the <code id=the-eventsource-interface:dom-eventsource-readystate-2><a href=#dom-eventsource-readystate>readyState</a></code> attribute to <code id=the-eventsource-interface:dom-eventsource-closed-2><a href=#dom-eventsource-closed>CLOSED</a></code>.</p>
   <dt><code><var>source</var>.<a href=#dom-eventsource-url id=dom-eventsource-url-dev>url</a></code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/EventSource/url title="The url read-only property of the EventSource interface returns a string representing the URL of the source.">EventSource/url</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>6+</span></span><span class="chrome yes"><span>Chrome</span><span>18+</span></span><hr><span class="opera yes"><span>Opera</span><span>12+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12+</span></span></div></div></div><dd><p>Returns the <a href=#concept-eventsource-url id=the-eventsource-interface:concept-eventsource-url-2>URL providing the event
   stream</a>.<dt><code><var>source</var>.<a href=#dom-eventsource-withcredentials id=dom-eventsource-withcredentials-dev>withCredentials</a></code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/EventSource/withCredentials title="The withCredentials read-only property of the EventSource interface returns a boolean value indicating whether the EventSource object was instantiated with CORS credentials set.">EventSource/withCredentials</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>7+</span></span><span class="chrome yes"><span>Chrome</span><span>26+</span></span><hr><span class="opera yes"><span>Opera</span><span>12+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios unknown"><span>Safari iOS</span><span>?</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12+</span></span></div></div></div><dd>
    <p>Returns true if the <a href=https://fetch.spec.whatwg.org/#concept-request-credentials-mode id=the-eventsource-interface:concept-request-credentials-mode-2 data-x-internal=concept-request-credentials-mode>credentials mode</a>
    for connection requests to the <a href=#concept-eventsource-url id=the-eventsource-interface:concept-eventsource-url-3>URL providing the event
    stream</a> is set to "<code>include</code>", and false otherwise.</p>
   <dt><code><var>source</var>.<a href=#dom-eventsource-readystate id=dom-eventsource-readystate-dev>readyState</a></code><div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/EventSource/readyState title="The readyState read-only property of the EventSource interface returns a number representing the state of the connection.">EventSource/readyState</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>5+</span></span><span class="chrome yes"><span>Chrome</span><span>6+</span></span><hr><span class="opera yes"><span>Opera</span><span>12+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>5+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12+</span></span></div></div></div><dd>
    <p>Returns the state of this <code id=the-eventsource-interface:eventsource-6><a href=#eventsource>EventSource</a></code> object's connection. It can have the
    values described below.</p>
   </dl>

  

  <p>The <dfn data-dfn-for=EventSource id=dom-eventsource data-dfn-type=constructor><code>EventSource(<var>url</var>, <var>eventSourceInitDict</var>)</code></dfn>
  constructor, when invoked, must run these steps:</p>

  <ol><li><p>Let <var>ev</var> be a new <code id=the-eventsource-interface:eventsource-7><a href=#eventsource>EventSource</a></code> object.<li><p>Let <var>settings</var> be <var>ev</var>'s <a id=the-eventsource-interface:relevant-settings-object href=webappapis.html#relevant-settings-object>relevant settings object</a>.

   <li><p>Let <var>urlRecord</var> be the result of <a id=the-eventsource-interface:encoding-parsing-a-url href=urls-and-fetching.html#encoding-parsing-a-url>encoding-parsing a URL</a> given
   <var>url</var>, relative to <var>settings</var>.<li><p>If <var>urlRecord</var> is failure, then throw a <a id=the-eventsource-interface:syntaxerror href=https://webidl.spec.whatwg.org/#syntaxerror data-x-internal=syntaxerror>"<code>SyntaxError</code>"</a>
   <code id=the-eventsource-interface:domexception><a data-x-internal=domexception href=https://webidl.spec.whatwg.org/#dfn-DOMException>DOMException</a></code>.<li><p>Set <var>ev</var>'s <a href=#concept-eventsource-url id=the-eventsource-interface:concept-eventsource-url-4>url</a> to
   <var>urlRecord</var>.</p>

   <li><p>Let <var>corsAttributeState</var> be <a href=urls-and-fetching.html#attr-crossorigin-anonymous id=the-eventsource-interface:attr-crossorigin-anonymous>Anonymous</a>.<li><p>If the value of <var>eventSourceInitDict</var>'s <code id=the-eventsource-interface:dom-eventsourceinit-withcredentials-3><a href=#dom-eventsourceinit-withcredentials>withCredentials</a></code> member is true, then set
   <var>corsAttributeState</var> to <a href=urls-and-fetching.html#attr-crossorigin-use-credentials id=the-eventsource-interface:attr-crossorigin-use-credentials>Use
   Credentials</a> and set <var>ev</var>'s <code id=the-eventsource-interface:dom-eventsource-withcredentials-2><a href=#dom-eventsource-withcredentials>withCredentials</a></code> attribute to true.<li><p>Let <var>request</var> be the result of <a href=urls-and-fetching.html#create-a-potential-cors-request id=the-eventsource-interface:create-a-potential-cors-request>creating a potential-CORS request</a> given
   <var>urlRecord</var>, the empty string, and <var>corsAttributeState</var>.<li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-client id=the-eventsource-interface:concept-request-client data-x-internal=concept-request-client>client</a> to
   <var>settings</var>.<li><p>User agents may <a href=https://fetch.spec.whatwg.org/#concept-header-list-set id=the-eventsource-interface:concept-header-list-set data-x-internal=concept-header-list-set>set</a> (`<code id=the-eventsource-interface:http-accept><a data-x-internal=http-accept href=https://httpwg.org/specs/rfc7231.html#header.accept>Accept</a></code>`, `<code id=the-eventsource-interface:text/event-stream><a href=iana.html#text/event-stream>text/event-stream</a></code>`) in <var>request</var>'s
   <a href=https://fetch.spec.whatwg.org/#concept-request-header-list id=the-eventsource-interface:concept-request-header-list data-x-internal=concept-request-header-list>header list</a>.<li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-cache-mode id=the-eventsource-interface:concept-request-cache-mode data-x-internal=concept-request-cache-mode>cache mode</a> to
   "<code>no-store</code>".<li><p>Set <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#request-initiator-type id=the-eventsource-interface:concept-request-initiator-type data-x-internal=concept-request-initiator-type>initiator
   type</a> to "<code>other</code>".<li><p>Set <var>ev</var>'s <a href=#concept-event-stream-request id=the-eventsource-interface:concept-event-stream-request>request</a> to
   <var>request</var>.<li><p>Let <var>processEventSourceEndOfBody</var> given <a href=https://fetch.spec.whatwg.org/#concept-response id=the-eventsource-interface:concept-response data-x-internal=concept-response>response</a> <var>res</var> be the following step: if
   <var>res</var> is not a <a id=the-eventsource-interface:network-error href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a>, then <a href=#reestablish-the-connection id=the-eventsource-interface:reestablish-the-connection>reestablish the
   connection</a>.<li>
    <p><a href=https://fetch.spec.whatwg.org/#concept-fetch id=the-eventsource-interface:concept-fetch-2 data-x-internal=concept-fetch>Fetch</a> <var>request</var>, with <i id=the-eventsource-interface:processresponseendofbody><a data-x-internal=processresponseendofbody href=https://fetch.spec.whatwg.org/#fetch-processresponseendofbody>processResponseEndOfBody</a></i> set to
    <var>processEventSourceEndOfBody</var> and <i id=the-eventsource-interface:processresponse><a data-x-internal=processresponse href=https://fetch.spec.whatwg.org/#process-response>processResponse</a></i> set
    to the following steps given <a href=https://fetch.spec.whatwg.org/#concept-response id=the-eventsource-interface:concept-response-2 data-x-internal=concept-response>response</a>
    <var>res</var>:</p>

    <ol><li><p>If <var>res</var> is an <a id=the-eventsource-interface:aborted-network-error href=https://fetch.spec.whatwg.org/#concept-aborted-network-error data-x-internal=aborted-network-error>aborted network error</a>, then <a href=#fail-the-connection id=the-eventsource-interface:fail-the-connection>fail the
     connection</a>.<li><p>Otherwise, if <var>res</var> is a <a id=the-eventsource-interface:network-error-2 href=https://fetch.spec.whatwg.org/#concept-network-error data-x-internal=network-error>network error</a>, then <a href=#reestablish-the-connection id=the-eventsource-interface:reestablish-the-connection-2>reestablish
     the connection</a>, unless the user agent knows that to be futile, in which case the user
     agent may <a href=#fail-the-connection id=the-eventsource-interface:fail-the-connection-2>fail the connection</a>.<li><p>Otherwise, if <var>res</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-status id=the-eventsource-interface:concept-response-status data-x-internal=concept-response-status>status</a> is
     not 200, or if <var>res</var>'s `<code id=the-eventsource-interface:content-type><a href=urls-and-fetching.html#content-type>Content-Type</a></code>` is not
     `<code id=the-eventsource-interface:text/event-stream-2><a href=iana.html#text/event-stream>text/event-stream</a></code>`, then <a href=#fail-the-connection id=the-eventsource-interface:fail-the-connection-3>fail the connection</a>.</p>

     <li><p>Otherwise, <a href=#announce-the-connection id=the-eventsource-interface:announce-the-connection>announce the connection</a> and <a href=#event-stream-interpretation>interpret</a> <var>res</var>'s <a href=https://fetch.spec.whatwg.org/#concept-response-body id=the-eventsource-interface:concept-response-body data-x-internal=concept-response-body>body</a> line by line.</ol>
   <li><p>Return <var>ev</var>.</ol>

  <hr>

  <p>The <dfn data-dfn-for=EventSource id=dom-eventsource-url data-dfn-type=attribute><code>url</code></dfn>
  attribute's getter must return the <a href=https://url.spec.whatwg.org/#concept-url-serializer id=the-eventsource-interface:concept-url-serializer data-x-internal=concept-url-serializer>serialization</a> of
  this <code id=the-eventsource-interface:eventsource-8><a href=#eventsource>EventSource</a></code> object's <a href=#concept-eventsource-url id=the-eventsource-interface:concept-eventsource-url-5>url</a>.</p>

  <p>The <dfn data-dfn-for=EventSource id=dom-eventsource-withcredentials data-dfn-type=attribute><code>withCredentials</code></dfn> attribute must return the
  value to which it was last initialized. When the object is created, it must be initialized to
  false.</p>

  <p>The <dfn data-dfn-for=EventSource id=dom-eventsource-readystate data-dfn-type=attribute><code>readyState</code></dfn> attribute represents the state of the
  connection. It can have the following values:</p>

  

  <dl><dt><dfn data-dfn-for=EventSource id=dom-eventsource-connecting data-dfn-type=const><code>CONNECTING</code></dfn> (numeric value 0)<dd>The connection has not yet been established, or it was closed and the user agent is
   reconnecting.<dt><dfn data-dfn-for=EventSource id=dom-eventsource-open data-dfn-type=const><code>OPEN</code></dfn> (numeric value 1)<dd>The user agent has an open connection and is dispatching events as it receives them.<dt><dfn data-dfn-for=EventSource id=dom-eventsource-closed data-dfn-type=const><code>CLOSED</code></dfn> (numeric value 2)<dd>The connection is not open, and the user agent is not trying to reconnect. Either there was a
   fatal error or the <code id=the-eventsource-interface:dom-eventsource-close-2><a href=#dom-eventsource-close>close()</a></code> method was invoked.</dl>

  

  <p>When the object is created, its <code id=the-eventsource-interface:dom-eventsource-readystate-3><a href=#dom-eventsource-readystate>readyState</a></code> must
  be set to <code id=the-eventsource-interface:dom-eventsource-connecting-2><a href=#dom-eventsource-connecting>CONNECTING</a></code> (0). The rules given below
  for handling the connection define when the value changes.</p>

  <p>The <dfn data-dfn-for=EventSource id=dom-eventsource-close data-dfn-type=method><code>close()</code></dfn>
  method must abort any instances of the <a href=https://fetch.spec.whatwg.org/#concept-fetch id=the-eventsource-interface:concept-fetch-3 data-x-internal=concept-fetch>fetch</a> algorithm started
  for this <code id=the-eventsource-interface:eventsource-9><a href=#eventsource>EventSource</a></code> object, and must set the <code id=the-eventsource-interface:dom-eventsource-readystate-4><a href=#dom-eventsource-readystate>readyState</a></code> attribute to <code id=the-eventsource-interface:dom-eventsource-closed-3><a href=#dom-eventsource-closed>CLOSED</a></code>.</p> 

  

  <p>The following are the <a id=the-eventsource-interface:event-handlers href=webappapis.html#event-handlers>event handlers</a> (and their corresponding <a href=webappapis.html#event-handler-event-type id=the-eventsource-interface:event-handler-event-type>event handler event types</a>) that must be supported,
  as <a id=the-eventsource-interface:event-handler-idl-attributes href=webappapis.html#event-handler-idl-attributes>event handler IDL attributes</a>, by all objects implementing the
  <code id=the-eventsource-interface:eventsource-10><a href=#eventsource>EventSource</a></code> interface:</p>

  <table><thead><tr><th><a href=webappapis.html#event-handlers id=the-eventsource-interface:event-handlers-2>Event handler</a> <th><a id=the-eventsource-interface:event-handler-event-type-2 href=webappapis.html#event-handler-event-type>Event handler event type</a>
   <tbody><tr><td><dfn data-dfn-for=EventSource id=handler-eventsource-onopen data-dfn-type=attribute><code>onopen</code></dfn> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/EventSource/open_event title="The open event of the EventSource API is fired when a connection with an event source is opened.">EventSource/open_event</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>5+</span></span><span class="chrome yes"><span>Chrome</span><span>6+</span></span><hr><span class="opera yes"><span>Opera</span><span>12+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>5+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12+</span></span></div></div></div><td> <code id=the-eventsource-interface:event-open><a href=indices.html#event-open>open</a></code>
    <tr><td><dfn data-dfn-for=EventSource id=handler-eventsource-onmessage data-dfn-type=attribute><code>onmessage</code></dfn> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/EventSource/message_event title="The message event of the EventSource API is fired when data is received through an event source.">EventSource/message_event</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>5+</span></span><span class="chrome yes"><span>Chrome</span><span>6+</span></span><hr><span class="opera yes"><span>Opera</span><span>12+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>5+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12+</span></span></div></div></div><td> <code id=the-eventsource-interface:event-message><a href=indices.html#event-message>message</a></code>
    <tr><td><dfn data-dfn-for=EventSource id=handler-eventsource-onerror data-dfn-type=attribute><code>onerror</code></dfn> <div class="mdn-anno wrapped before"><button onclick=toggleStatus(this) class=mdn-anno-btn><b title="Support in all current engines." class=all-engines-flag>✔</b><span>MDN</span></button><div class=feature><p><a href=https://developer.mozilla.org/en-US/docs/Web/API/EventSource/error_event title="The error event of the EventSource API is fired when a connection with an event source fails to be opened.">EventSource/error_event</a><p class=all-engines-text>Support in all current engines.<div class=support><span class="firefox yes"><span>Firefox</span><span>6+</span></span><span class="safari yes"><span>Safari</span><span>5+</span></span><span class="chrome yes"><span>Chrome</span><span>6+</span></span><hr><span class="opera yes"><span>Opera</span><span>12+</span></span><span class="edge_blink yes"><span>Edge</span><span>79+</span></span><hr><span class="edge unknown"><span>Edge (Legacy)</span><span>?</span></span><span class="ie no"><span>Internet Explorer</span><span>No</span></span><hr><span class="firefox_android yes"><span>Firefox Android</span><span>45+</span></span><span class="safari_ios yes"><span>Safari iOS</span><span>5+</span></span><span class="chrome_android unknown"><span>Chrome Android</span><span>?</span></span><span class="webview_android unknown"><span>WebView Android</span><span>?</span></span><span class="samsunginternet_android unknown"><span>Samsung Internet</span><span>?</span></span><span class="opera_android yes"><span>Opera Android</span><span>12+</span></span></div></div></div><td> <code id=the-eventsource-interface:event-error><a href=indices.html#event-error>error</a></code>
  </table>

  <hr>

  

  <h4 id=sse-processing-model><span class=secno>9.2.3</span> <span id=processing-model-9></span>Processing model<a href=#sse-processing-model class=self-link></a></h4>

  <p>When a user agent is to <dfn id=announce-the-connection>announce the connection</dfn>, the user agent must <a id=sse-processing-model:queue-a-task href=webappapis.html#queue-a-task>queue a
  task</a> which, if the <code id=sse-processing-model:dom-eventsource-readystate><a href=#dom-eventsource-readystate>readyState</a></code> attribute is
  set to a value other than <code id=sse-processing-model:dom-eventsource-closed><a href=#dom-eventsource-closed>CLOSED</a></code>, sets the <code id=sse-processing-model:dom-eventsource-readystate-2><a href=#dom-eventsource-readystate>readyState</a></code> attribute to <code id=sse-processing-model:dom-eventsource-open><a href=#dom-eventsource-open>OPEN</a></code> and <a href=https://dom.spec.whatwg.org/#concept-event-fire id=sse-processing-model:concept-event-fire data-x-internal=concept-event-fire>fires an
  event</a> named <code id=sse-processing-model:event-open><a href=indices.html#event-open>open</a></code> at the <code id=sse-processing-model:eventsource><a href=#eventsource>EventSource</a></code>
  object.</p>

  <p>When a user agent is to <dfn id=reestablish-the-connection>reestablish the connection</dfn>, the user agent must run the
  following steps. These steps are run <a id=sse-processing-model:in-parallel href=infrastructure.html#in-parallel>in parallel</a>, not as part of a <a href=webappapis.html#concept-task id=sse-processing-model:concept-task>task</a>. (The tasks that it queues, of course, are run like normal tasks
  and not themselves <a id=sse-processing-model:in-parallel-2 href=infrastructure.html#in-parallel>in parallel</a>.)</p>

  <ol><li>
    <p><a id=sse-processing-model:queue-a-task-2 href=webappapis.html#queue-a-task>Queue a task</a> to run the following steps:</p>

    <ol><li><p>If the <code id=sse-processing-model:dom-eventsource-readystate-3><a href=#dom-eventsource-readystate>readyState</a></code> attribute is set to
     <code id=sse-processing-model:dom-eventsource-closed-2><a href=#dom-eventsource-closed>CLOSED</a></code>, abort the task.<li><p>Set the <code id=sse-processing-model:dom-eventsource-readystate-4><a href=#dom-eventsource-readystate>readyState</a></code> attribute to <code id=sse-processing-model:dom-eventsource-connecting><a href=#dom-eventsource-connecting>CONNECTING</a></code>.<li><p><a href=https://dom.spec.whatwg.org/#concept-event-fire id=sse-processing-model:concept-event-fire-2 data-x-internal=concept-event-fire>Fire an event</a> named <code id=sse-processing-model:event-error><a href=indices.html#event-error>error</a></code> at the <code id=sse-processing-model:eventsource-2><a href=#eventsource>EventSource</a></code> object.</ol>
   <li><p>Wait a delay equal to the reconnection time of the event source.<li><p>Optionally, wait some more. In particular, if the previous attempt failed, then user
   agents might introduce an exponential backoff delay to avoid overloading a potentially already
   overloaded server. Alternatively, if the operating system has reported that there is no network
   connectivity, user agents might wait for the operating system to announce that the network
   connection has returned before retrying.<li><p>Wait until the aforementioned task has run, if it has not yet run.<li>
    <p><a id=sse-processing-model:queue-a-task-3 href=webappapis.html#queue-a-task>Queue a task</a> to run the following steps:</p>

    <ol><li><p>If the <code id=sse-processing-model:eventsource-3><a href=#eventsource>EventSource</a></code> object's <code id=sse-processing-model:dom-eventsource-readystate-5><a href=#dom-eventsource-readystate>readyState</a></code> attribute is not set to <code id=sse-processing-model:dom-eventsource-connecting-2><a href=#dom-eventsource-connecting>CONNECTING</a></code>, then return.<li><p>Let <var>request</var> be the <code id=sse-processing-model:eventsource-4><a href=#eventsource>EventSource</a></code> object's <a href=#concept-event-stream-request id=sse-processing-model:concept-event-stream-request>request</a>.

     <li>
      <p>If the <code id=sse-processing-model:eventsource-5><a href=#eventsource>EventSource</a></code> object's <a href=#concept-event-stream-last-event-id id=sse-processing-model:concept-event-stream-last-event-id>last event ID string</a> is not the empty
      string, then:</p>

      <ol><li><p>Let <var>lastEventIDValue</var> be the <code id=sse-processing-model:eventsource-6><a href=#eventsource>EventSource</a></code> object's <a href=#concept-event-stream-last-event-id id=sse-processing-model:concept-event-stream-last-event-id-2>last event ID string</a>, <a href=https://encoding.spec.whatwg.org/#utf-8-encode id=sse-processing-model:utf-8-encode data-x-internal=utf-8-encode>encoded as UTF-8</a>.<li><p><a href=https://fetch.spec.whatwg.org/#concept-header-list-set id=sse-processing-model:concept-header-list-set data-x-internal=concept-header-list-set>Set</a> (`<code id=sse-processing-model:last-event-id><a href=#last-event-id>Last-Event-ID</a></code>`,
       <var>lastEventIDValue</var>) in <var>request</var>'s <a href=https://fetch.spec.whatwg.org/#concept-request-header-list id=sse-processing-model:concept-request-header-list data-x-internal=concept-request-header-list>header list</a>.</ol>
     <li><p><a href=https://fetch.spec.whatwg.org/#concept-fetch id=sse-processing-model:concept-fetch data-x-internal=concept-fetch>Fetch</a> <var>request</var> and process the
     response obtained in this fashion, if any, as described earlier in this section.</ol>
   </ol>

  <p>When a user agent is to <dfn id=fail-the-connection>fail the connection</dfn>, the user agent must <a id=sse-processing-model:queue-a-task-4 href=webappapis.html#queue-a-task>queue a
  task</a> which, if the <code id=sse-processing-model:dom-eventsource-readystate-6><a href=#dom-eventsource-readystate>readyState</a></code> attribute is
  set to a value other than <code id=sse-processing-model:dom-eventsource-closed-3><a href=#dom-eventsource-closed>CLOSED</a></code>, sets the <code id=sse-processing-model:dom-eventsource-readystate-7><a href=#dom-eventsource-readystate>readyState</a></code> attribute to <code id=sse-processing-model:dom-eventsource-closed-4><a href=#dom-eventsource-closed>CLOSED</a></code> and <a href=https://dom.spec.whatwg.org/#concept-event-fire id=sse-processing-model:concept-event-fire-3 data-x-internal=concept-event-fire>fires an
  event</a> named <code id=sse-processing-model:event-error-2><a href=indices.html#event-error>error</a></code> at the <code id=sse-processing-model:eventsource-7><a href=#eventsource>EventSource</a></code> object.
  <strong>Once the user agent has <a href=#fail-the-connection id=sse-processing-model:fail-the-connection>failed the connection</a>,
  it does <em>not</em> attempt to reconnect.</strong></p>

  <hr>

  <p>The <a id=sse-processing-model:task-source href=webappapis.html#task-source>task source</a> for any <a href=webappapis.html#concept-task id=sse-processing-model:concept-task-2>tasks</a> that are <a href=webappapis.html#queue-a-task id=sse-processing-model:queue-a-task-5>queued</a> by <code id=sse-processing-model:eventsource-8><a href=#eventsource>EventSource</a></code> objects is the <dfn id=remote-event-task-source>remote event
  task source</dfn>.</p>

  


  <h4 id=the-last-event-id-header><span class=secno>9.2.4</span> The `<code id=the-last-event-id-header:last-event-id><a href=#last-event-id>Last-Event-ID</a></code>` header<a href=#the-last-event-id-header class=self-link></a></h4>

  <p>The <dfn id=last-event-id data-dfn-type=http-header><code>Last-Event-ID</code></dfn>` HTTP request header reports an
  <code id=the-last-event-id-header:eventsource><a href=#eventsource>EventSource</a></code> object's <a href=#concept-event-stream-last-event-id id=the-last-event-id-header:concept-event-stream-last-event-id>last event ID
  string</a> to the server when the user agent is to <a href=#reestablish-the-connection id=the-last-event-id-header:reestablish-the-connection>reestablish the connection</a>.

  <p class=XXX>See <a href=https://github.com/whatwg/html/issues/7363>whatwg/html issue
  #7363</a> to define the value space better. It is essentially any UTF-8 encoded string, that does
  not contain U+0000 NULL, U+000A LF, or U+000D CR.</p>


  <h4 id=parsing-an-event-stream><span class=secno>9.2.5</span> Parsing an event stream<a href=#parsing-an-event-stream class=self-link></a></h4>

  

  <p>This event stream format's <a id=parsing-an-event-stream:mime-type href=https://mimesniff.spec.whatwg.org/#mime-type data-x-internal=mime-type>MIME type</a> is <code id=parsing-an-event-stream:text/event-stream><a href=iana.html#text/event-stream>text/event-stream</a></code>.</p>

  <p>The event stream format is as described by the <code>stream</code> production of the
  following ABNF, the character set for which is Unicode. <a href=references.html#refsABNF>[ABNF]</a></p>

  <pre><code class='abnf'><c- nc>stream</c->        <c- o>=</c-> <c- p>[</c-> <c- nc>bom</c-> <c- p>]</c-> <c- o>*</c-><c- nc>event</c->
<c- nc>event</c->         <c- o>=</c-> <c- o>*</c-><c- p>(</c-> <c- nc>comment</c-> <c- o>/</c-> <c- nc>field</c-> <c- p>)</c-> <c- nc>end-of-line</c->
<c- nc>comment</c->       <c- o>=</c-> <c- nc>colon</c-> <c- o>*</c-><c- nc>any-char</c-> <c- nc>end-of-line</c->
<c- nc>field</c->         <c- o>=</c-> <c- o>1*</c-><c- nc>name-char</c-> <c- p>[</c-> <c- nc>colon</c-> <c- p>[</c-> <c- nc>space</c-> <c- p>]</c-> <c- o>*</c-><c- nc>any-char</c-> <c- p>]</c-> <c- nc>end-of-line</c->
<c- nc>end-of-line</c->   <c- o>=</c-> <c- p>(</c-> <c- nc>cr</c-> <c- nc>lf</c-> <c- o>/</c-> <c- nc>cr</c-> <c- o>/</c-> <c- nc>lf</c-> <c- p>)</c->

<c- c1>; characters</c->
<c- nc>lf</c->            <c- o>=</c-> <c- l>%x000A</c-> <c- c1>; U+000A LINE FEED (LF)</c->
<c- nc>cr</c->            <c- o>=</c-> <c- l>%x000D</c-> <c- c1>; U+000D CARRIAGE RETURN (CR)</c->
<c- nc>space</c->         <c- o>=</c-> <c- l>%x0020</c-> <c- c1>; U+0020 SPACE</c->
<c- nc>colon</c->         <c- o>=</c-> <c- l>%x003A</c-> <c- c1>; U+003A COLON (:)</c->
<c- nc>bom</c->           <c- o>=</c-> <c- l>%xFEFF</c-> <c- c1>; U+FEFF BYTE ORDER MARK</c->
<c- nc>name-char</c->     <c- o>=</c-> <c- l>%x0000-0009</c-> <c- o>/</c-> <c- l>%x000B-000C</c-> <c- o>/</c-> <c- l>%x000E-0039</c-> <c- o>/</c-> <c- l>%x003B-10FFFF</c->
                <c- c1>; a </c-><a id='parsing-an-event-stream:scalar-value' href='https://infra.spec.whatwg.org/#scalar-value' data-x-internal='scalar-value'><c- c1>scalar value</c-></a><c- c1> other than U+000A LINE FEED (LF), U+000D CARRIAGE RETURN (CR), or U+003A COLON (:)</c->
<c- nc>any-char</c->      <c- o>=</c-> <c- l>%x0000-0009</c-> <c- o>/</c-> <c- l>%x000B-000C</c-> <c- o>/</c-> <c- l>%x000E-10FFFF</c->
                <c- c1>; a </c-><a id='parsing-an-event-stream:scalar-value-2' href='https://infra.spec.whatwg.org/#scalar-value' data-x-internal='scalar-value'><c- c1>scalar value</c-></a><c- c1> other than U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR)</c-></code></pre>

  <p>Event streams in this format must always be encoded as UTF-8. <a href=references.html#refsENCODING>[ENCODING]</a></p>

  <p>Lines must be separated by either a U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character
  pair, a single U+000A LINE FEED (LF) character, or a single U+000D CARRIAGE RETURN (CR)
  character.</p>

  <p>Since connections established to remote servers for such resources are expected to be
  long-lived, UAs should ensure that appropriate buffering is used. In particular, while line
  buffering with lines are defined to end with a single U+000A LINE FEED (LF) character is safe,
  block buffering or line buffering with different expected line endings can cause delays in event
  dispatch.</p>


  

  <h4 id=event-stream-interpretation><span class=secno>9.2.6</span> Interpreting an event stream<a href=#event-stream-interpretation class=self-link></a></h4>

  <p>Streams must be decoded using the <a id=event-stream-interpretation:utf-8-decode href=https://encoding.spec.whatwg.org/#utf-8-decode data-x-internal=utf-8-decode>UTF-8 decode</a> algorithm.</p>

  <p class=note>The <a id=event-stream-interpretation:utf-8-decode-2 href=https://encoding.spec.whatwg.org/#utf-8-decode data-x-internal=utf-8-decode>UTF-8 decode</a> algorithm strips one leading UTF-8 Byte Order Mark
  (BOM), if any.</p>

  <p>The stream must then be parsed by reading everything line by line, with a U+000D CARRIAGE
  RETURN U+000A LINE FEED (CRLF) character pair, a single U+000A LINE FEED (LF) character not
  preceded by a U+000D CARRIAGE RETURN (CR) character, and a single U+000D CARRIAGE RETURN (CR)
  character not followed by a U+000A LINE FEED (LF) character being the ways in which a line can
  end.</p>

  <p>When a stream is parsed, a <var>data</var> buffer, an <var>event type</var>
  buffer, and a <var>last event ID</var> buffer must be associated with it. They must be
  initialized to the empty string.</p>

  <p>Lines must be processed, in the order they are received, as follows:</p>

  <dl class=switch><dt>If the line is empty (a blank line)<dd><p><a href=#dispatchMessage id=event-stream-interpretation:dispatchMessage>Dispatch the event</a>, as defined below.<dt>If the line starts with a U+003A COLON character (:)<dd><p>Ignore the line.<dt>If the line contains a U+003A COLON character (:)<dd>
    <p>Collect the characters on the line before the first U+003A COLON character (:), and let <var>field</var> be that string.</p>

    <p>Collect the characters on the line after the first U+003A COLON character (:), and let <var>value</var> be that string. If <var>value</var> starts with a U+0020 SPACE
    character, remove it from <var>value</var>.</p>

    <p><a href=#processField>Process the field</a> using the steps described below, using <var>field</var> as the field name and <var>value</var> as the field value.</p>
   <dt>Otherwise, the string is not empty but does not contain a U+003A COLON character (:)<dd>
    <p><a href=#processField>Process the field</a> using the steps described below, using the
    whole line as the field name, and the empty string as the field value.</p>
   </dl>

  <p>Once the end of the file is reached, any pending data must be discarded. (If the file ends in
  the middle of an event, before the final empty line, the incomplete event is not dispatched.)</p>

  <hr>

  <p id=processField>The steps to <dfn>process the field</dfn> given a field name and a
  field value depend on the field name, as given in the following list. Field names must be compared
  literally, with no case folding performed.</p>

  <dl class=switch><dt>If the field name is "event"<dd><p>Set the <var>event type</var> buffer to the field value.<dt>If the field name is "data"<dd><p>Append the field value to the <var>data</var> buffer, then append a single U+000A
   LINE FEED (LF) character to the <var>data</var> buffer.<dt>If the field name is "id"<dd><p>If the field value does not contain U+0000 NULL, then set the <var>last event ID</var>
   buffer to the field value. Otherwise, ignore the field.<dt>If the field name is "retry"<dd><p>If the field value consists of only <a id=event-stream-interpretation:ascii-digits href=https://infra.spec.whatwg.org/#ascii-digit data-x-internal=ascii-digits>ASCII digits</a>, then interpret the field
   value as an integer in base ten, and set the event stream's <a href=#concept-event-stream-reconnection-time id=event-stream-interpretation:concept-event-stream-reconnection-time>reconnection time</a> to that integer.
   Otherwise, ignore the field.<dt>Otherwise<dd><p>The field is ignored.</dl>


  <p>When the user agent is required to <dfn id=dispatchMessage>dispatch the
  event</dfn>, the user agent must process the <var>data</var> buffer, the <var>event type</var> buffer, and the <var>last event ID</var> buffer using steps
  appropriate for the user agent.</p>

  <p>For web browsers, the appropriate steps to <a href=#dispatchMessage id=event-stream-interpretation:dispatchMessage-2>dispatch the event</a> are as follows:</p>

  <ol><li><p>Set the <a href=#concept-event-stream-last-event-id id=event-stream-interpretation:concept-event-stream-last-event-id>last event ID string</a> of
   the event source to the value of the <var>last event ID</var> buffer. The buffer does
   not get reset, so the <a href=#concept-event-stream-last-event-id id=event-stream-interpretation:concept-event-stream-last-event-id-2>last event ID
   string</a> of the event source remains set to this value until the next time it is set by the
   server.<li><p>If the <var>data</var> buffer is an empty string, set the <var>data</var> buffer and the <var>event type</var> buffer to the empty string and
   return.<li><p>If the <var>data</var> buffer's last character is a U+000A LINE FEED (LF)
   character, then remove the last character from the <var>data</var> buffer.<li><p>Let <var>event</var> be the result of <a id=event-stream-interpretation:creating-an-event href=https://dom.spec.whatwg.org/#concept-event-create data-x-internal=creating-an-event>creating an event</a> using
   <code id=event-stream-interpretation:messageevent><a href=comms.html#messageevent>MessageEvent</a></code>, in the <a href=webappapis.html#concept-relevant-realm id=event-stream-interpretation:concept-relevant-realm>relevant realm</a> of
   the <code id=event-stream-interpretation:eventsource><a href=#eventsource>EventSource</a></code> object.<li><p>Initialize <var>event</var>'s <code id=event-stream-interpretation:dom-event-type><a data-x-internal=dom-event-type href=https://dom.spec.whatwg.org/#dom-event-type>type</a></code> attribute to
   "<code id=event-stream-interpretation:event-message><a href=indices.html#event-message>message</a></code>", its <code id=event-stream-interpretation:dom-messageevent-data><a href=comms.html#dom-messageevent-data>data</a></code> attribute to <var>data</var>, its <code id=event-stream-interpretation:dom-messageevent-origin><a href=comms.html#dom-messageevent-origin>origin</a></code> attribute to the <a href=browsers.html#ascii-serialisation-of-an-origin id=event-stream-interpretation:ascii-serialisation-of-an-origin>serialization</a> of the <a href=https://url.spec.whatwg.org/#concept-url-origin id=event-stream-interpretation:concept-url-origin data-x-internal=concept-url-origin>origin</a> of the
   event stream's final URL (i.e., the URL after redirects), and its <code id=event-stream-interpretation:dom-messageevent-lasteventid><a href=comms.html#dom-messageevent-lasteventid>lastEventId</a></code> attribute to the <a href=#concept-event-stream-last-event-id id=event-stream-interpretation:concept-event-stream-last-event-id-3>last event ID string</a> of the event
   source.<li><p>If the <var>event type</var> buffer has a value other than the empty string, change the
   <a href=https://dom.spec.whatwg.org/#dom-event-type id=event-stream-interpretation:concept-event-type data-x-internal=concept-event-type>type</a> of the newly created event to equal the value of
   the <var>event type</var> buffer.<li><p>Set the <var>data</var> buffer and the <var>event type</var> buffer to
   the empty string.<li><p><a id=event-stream-interpretation:queue-a-task href=webappapis.html#queue-a-task>Queue a task</a> which, if the <code id=event-stream-interpretation:dom-eventsource-readystate><a href=#dom-eventsource-readystate>readyState</a></code> attribute is set to a value other than <code id=event-stream-interpretation:dom-eventsource-closed><a href=#dom-eventsource-closed>CLOSED</a></code>, <a href=https://dom.spec.whatwg.org/#concept-event-dispatch id=event-stream-interpretation:concept-event-dispatch data-x-internal=concept-event-dispatch>dispatches</a> the newly created event at the
   <code id=event-stream-interpretation:eventsource-2><a href=#eventsource>EventSource</a></code> object.</ol>

  <p class=note>If an event doesn't have an "id" field, but an earlier event did set the event
  source's <a href=#concept-event-stream-last-event-id id=event-stream-interpretation:concept-event-stream-last-event-id-4>last event ID string</a>, then the
  event's <code id=event-stream-interpretation:dom-messageevent-lasteventid-2><a href=comms.html#dom-messageevent-lasteventid>lastEventId</a></code> field will be set to the
  value of whatever the last seen "id" field was.</p>

  <p>For other user agents, the appropriate steps to <a href=#dispatchMessage id=event-stream-interpretation:dispatchMessage-3>dispatch the event</a> are
  implementation dependent, but at a minimum they must set the <var>data</var> and <var>event type</var> buffers to the empty string before returning.</p>

  

  <div class=example>
   <p>The following event stream, once followed by a blank line:</p>
   <pre>data: YHOO
data: +2
data: 10</pre>

   <p>...would cause an event <code id=event-stream-interpretation:event-message-2><a href=indices.html#event-message>message</a></code> with the interface
   <code id=event-stream-interpretation:messageevent-2><a href=comms.html#messageevent>MessageEvent</a></code> to be dispatched on the <code id=event-stream-interpretation:eventsource-3><a href=#eventsource>EventSource</a></code> object. The event's
   <code id=event-stream-interpretation:dom-messageevent-data-2><a href=comms.html#dom-messageevent-data>data</a></code> attribute would contain the string "<code>YHOO\n+2\n10</code>" (where "<code>\n</code>" represents a newline).</p>

   <p>This could be used as follows:
   <pre><code class='js'><c- a>var</c-> stocks <c- o>=</c-> <c- k>new</c-> EventSource<c- p>(</c-><c- u>&quot;https://stocks.example.com/ticker.php&quot;</c-><c- p>);</c->
stocks<c- p>.</c->onmessage <c- o>=</c-> <c- a>function</c-> <c- p>(</c->event<c- p>)</c-> <c- p>{</c->
  <c- a>var</c-> data <c- o>=</c-> event<c- p>.</c->data<c- p>.</c->split<c- p>(</c-><c- t>&apos;\n&apos;</c-><c- p>);</c->
  updateStocks<c- p>(</c->data<c- p>[</c-><c- mf>0</c-><c- p>],</c-> data<c- p>[</c-><c- mf>1</c-><c- p>],</c-> data<c- p>[</c-><c- mf>2</c-><c- p>]);</c->
<c- p>};</c-></code></pre>

   <p>...where <code>updateStocks()</code> is a function defined as:</p>

   <pre><code class='js'><c- a>function</c-> updateStocks<c- p>(</c->symbol<c- p>,</c-> delta<c- p>,</c-> value<c- p>)</c-> <c- p>{</c-> <c- p>...</c-> <c- p>}</c-></code></pre>

   <p>...or some such.</p>
  </div>

  <div class=example>
   <p>The following stream contains four blocks. The first block has just a comment, and will fire
   nothing. The second block has two fields with names "data" and "id" respectively; an event will
   be fired for this block, with the data "first event", and will then set the last event ID to "1"
   so that if the connection died between this block and the next, the server would be sent a
   `<code id=event-stream-interpretation:last-event-id><a href=#last-event-id>Last-Event-ID</a></code>` header with the value `<code>1</code>`. The third block
   fires an event with data "second event", and also has an "id" field, this time with no value,
   which resets the last event ID to the empty string (meaning no `<code id=event-stream-interpretation:last-event-id-2><a href=#last-event-id>Last-Event-ID</a></code>`
   header will now be sent in the event of a reconnection being attempted). Finally, the last block
   just fires an event with the data " third event" (with a single leading space
   character). Note that the last still has to end with a blank line, the end of the stream is not
   enough to trigger the dispatch of the last event.</p>

   <pre>: test stream

data: first event
id: 1

data:second event
id

data:  third event
</pre>
  </div>

  <div class=example>
   <p>The following stream fires two events:</p>

   <pre>data

data
data

data:</pre>

   <p>The first block fires events with the data set to the empty string, as would the last block if
   it was followed by a blank line. The middle block fires an event with the data set to a single
   newline character. The last block is discarded because it is not followed by a blank line.</p>
  </div>

  <div class=example>
   <p>The following stream fires two identical events:</p>

   <pre>data:test

data: test
</pre>

   <p>This is because the space after the colon is ignored if present.</p>
  </div>


  <h4 id=authoring-notes><span class=secno>9.2.7</span> Authoring notes<a href=#authoring-notes class=self-link></a></h4>

  <p>Legacy proxy servers are known to, in certain cases, drop HTTP connections after a short
  timeout. To protect against such proxy servers, authors can include a comment line (one starting
  with a ':' character) every 15 seconds or so.</p>

  <p>Authors wishing to relate event source connections to each other or to specific documents
  previously served might find that relying on IP addresses doesn't work, as individual clients can
  have multiple IP addresses (due to having multiple proxy servers) and individual IP addresses can
  have multiple clients (due to sharing a proxy server). It is better to include a unique identifier
  in the document when it is served and then pass that identifier as part of the URL when the
  connection is established.</p>

  <p>Authors are also cautioned that HTTP chunking can have unexpected negative effects on the
  reliability of this protocol, in particular if the chunking is done by a different layer unaware
  of the timing requirements. If this is a problem, chunking can be disabled for serving event
  streams.</p> 

  <p>Clients that support HTTP's per-server connection limitation might run into trouble when
  opening multiple pages from a site if each page has an <code id=authoring-notes:eventsource><a href=#eventsource>EventSource</a></code> to the same
  domain. Authors can avoid this using the relatively complex mechanism of using unique domain names
  per connection, or by allowing the user to enable or disable the <code id=authoring-notes:eventsource-2><a href=#eventsource>EventSource</a></code>
  functionality on a per-page basis, or by sharing a single <code id=authoring-notes:eventsource-3><a href=#eventsource>EventSource</a></code> object using a
  <a href=workers.html#sharedworkerglobalscope id=authoring-notes:sharedworkerglobalscope>shared worker</a>.</p>

  

  <h4 id=eventsource-push><span class=secno>9.2.8</span> Connectionless push and other features<a href=#eventsource-push class=self-link></a></h4>

  <p>User agents running in controlled environments, e.g. browsers on mobile handsets tied to
  specific carriers, may offload the management of the connection to a proxy on the network. In such
  a situation, the user agent for the purposes of conformance is considered to include both the
  handset software and the network proxy.</p>

  <div class=example>

   <p>For example, a browser on a mobile device, after having established a connection, might detect
   that it is on a supporting network and request that a proxy server on the network take over the
   management of the connection. The timeline for such a situation might be as follows:</p>

   <ol><li>Browser connects to a remote HTTP server and requests the resource specified by the author
    in the <code id=eventsource-push:dom-eventsource><a href=#dom-eventsource>EventSource</a></code> constructor.<li>The server sends occasional messages.<li>In between two messages, the browser detects that it is idle except for the network activity
    involved in keeping the TCP connection alive, and decides to switch to sleep mode to save
    power.<li>The browser disconnects from the server.<li>The browser contacts a service on the network, and requests that the service, a "push
    proxy", maintain the connection instead.<li>The "push proxy" service contacts the remote HTTP server and requests the resource specified
    by the author in the <code id=eventsource-push:dom-eventsource-2><a href=#dom-eventsource>EventSource</a></code> constructor (possibly
    including a `<code id=eventsource-push:last-event-id><a href=#last-event-id>Last-Event-ID</a></code>` HTTP header, etc.).<li>The browser allows the mobile device to go to sleep.<li>The server sends another message.<li>The "push proxy" service uses a technology such as OMA push to convey the event to the
    mobile device, which wakes only enough to process the event and then returns to sleep.</ol>

  </div>

  <p>This can reduce the total data usage, and can therefore result in considerable power
  savings.</p>

  <p>As well as implementing the existing API and <code id=eventsource-push:text/event-stream><a href=iana.html#text/event-stream>text/event-stream</a></code> wire format as
  defined by this specification and in more distributed ways as described above, formats of event
  framing defined by <a id=eventsource-push:other-applicable-specifications href=infrastructure.html#other-applicable-specifications>other applicable specifications</a> may be supported. This
  specification does not define how they are to be parsed or processed.</p>


  <h4 id=garbage-collection><span class=secno>9.2.9</span> Garbage collection<a href=#garbage-collection class=self-link></a></h4>

  <p>While an <code id=garbage-collection:eventsource><a href=#eventsource>EventSource</a></code> object's <code id=garbage-collection:dom-eventsource-readystate><a href=#dom-eventsource-readystate>readyState</a></code> is <code id=garbage-collection:dom-eventsource-connecting><a href=#dom-eventsource-connecting>CONNECTING</a></code>, and the object has one or more event
  listeners registered for <code id=garbage-collection:event-open><a href=indices.html#event-open>open</a></code>, <code id=garbage-collection:event-message><a href=indices.html#event-message>message</a></code>, or <code id=garbage-collection:event-error><a href=indices.html#event-error>error</a></code> events, there must
  be a strong reference from the <code id=garbage-collection:window><a href=nav-history-apis.html#window>Window</a></code> or <code id=garbage-collection:workerglobalscope><a href=workers.html#workerglobalscope>WorkerGlobalScope</a></code> object that
  the <code id=garbage-collection:eventsource-2><a href=#eventsource>EventSource</a></code> object's constructor was invoked from to the <code id=garbage-collection:eventsource-3><a href=#eventsource>EventSource</a></code>
  object itself.</p>

  <p>While an <code id=garbage-collection:eventsource-4><a href=#eventsource>EventSource</a></code> object's <code id=garbage-collection:dom-eventsource-readystate-2><a href=#dom-eventsource-readystate>readyState</a></code> is <code id=garbage-collection:dom-eventsource-open><a href=#dom-eventsource-open>OPEN</a></code>, and the object has one or more event listeners
  registered for <code id=garbage-collection:event-message-2><a href=indices.html#event-message>message</a></code> or <code id=garbage-collection:event-error-2><a href=indices.html#event-error>error</a></code> events, there must be a strong reference from the
  <code id=garbage-collection:window-2><a href=nav-history-apis.html#window>Window</a></code> or <code id=garbage-collection:workerglobalscope-2><a href=workers.html#workerglobalscope>WorkerGlobalScope</a></code> object that the <code id=garbage-collection:eventsource-5><a href=#eventsource>EventSource</a></code>
  object's constructor was invoked from to the <code id=garbage-collection:eventsource-6><a href=#eventsource>EventSource</a></code> object itself.</p>

  <p>While there is a task queued by an <code id=garbage-collection:eventsource-7><a href=#eventsource>EventSource</a></code> object on the <a href=#remote-event-task-source id=garbage-collection:remote-event-task-source>remote event
  task source</a>, there must be a strong reference from the <code id=garbage-collection:window-3><a href=nav-history-apis.html#window>Window</a></code> or
  <code id=garbage-collection:workerglobalscope-3><a href=workers.html#workerglobalscope>WorkerGlobalScope</a></code> object that the <code id=garbage-collection:eventsource-8><a href=#eventsource>EventSource</a></code> object's constructor was
  invoked from to that <code id=garbage-collection:eventsource-9><a href=#eventsource>EventSource</a></code> object.</p>

  <p>If a user agent is to <dfn id=concept-eventsource-forcibly-close>forcibly close</dfn> an
  <code id=garbage-collection:eventsource-10><a href=#eventsource>EventSource</a></code> object (this happens when a <code id=garbage-collection:document><a href=dom.html#document>Document</a></code> object goes away
  permanently), the user agent must abort any instances of the <a href=https://fetch.spec.whatwg.org/#concept-fetch id=garbage-collection:concept-fetch data-x-internal=concept-fetch>fetch</a> algorithm started for this <code id=garbage-collection:eventsource-11><a href=#eventsource>EventSource</a></code> object,
  and must set the <code id=garbage-collection:dom-eventsource-readystate-3><a href=#dom-eventsource-readystate>readyState</a></code> attribute to <code id=garbage-collection:dom-eventsource-closed><a href=#dom-eventsource-closed>CLOSED</a></code>.</p> 

  <p>If an <code id=garbage-collection:eventsource-12><a href=#eventsource>EventSource</a></code> object is garbage collected while its connection is still open,
  the user agent must abort any instance of the <a href=https://fetch.spec.whatwg.org/#concept-fetch id=garbage-collection:concept-fetch-2 data-x-internal=concept-fetch>fetch</a> algorithm
  opened by this <code id=garbage-collection:eventsource-13><a href=#eventsource>EventSource</a></code>.</p> 


  <h4 id=implementation-advice><span class=secno>9.2.10</span> Implementation advice<a href=#implementation-advice class=self-link></a></h4>

  <p><i>This section is non-normative.</i></p>

  <p>User agents are strongly urged to provide detailed diagnostic information about
  <code id=implementation-advice:eventsource><a href=#eventsource>EventSource</a></code> objects and their related network connections in their development
  consoles, to aid authors in debugging code using this API.</p>

  <p>For example, a user agent could have a panel displaying all the <code id=implementation-advice:eventsource-2><a href=#eventsource>EventSource</a></code>
  objects a page has created, each listing the constructor's arguments, whether there was a network
  error, what the CORS status of the connection is and what headers were sent by the client and
  received from the server to lead to that status, the messages that were received and how they were
  parsed, and so forth.</p>

  <p>Implementations are especially encouraged to report detailed information to their development
  consoles whenever an <code id=implementation-advice:event-error><a href=indices.html#event-error>error</a></code> event is fired, since little to no
  information can be made available in the events themselves.</p>

  


  <nav><a href=comms.html>← 9 Communication</a> — <a href=index.html>Table of Contents</a> — <a href=web-messaging.html>9.3 Cross-document messaging →</a></nav>
